package net.ys.controller;

import net.ys.service.ApiService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: NMY
 * @Date: 2021/11/3
 * @Time: 16:48
 */
@RestController
public class ApiController {

    @Resource
    private ApiService apiService;

    @GetMapping("/images")
    public Object images(String prjName) throws UnsupportedEncodingException {
        if (prjName == null) {
            return "need prjName";
        }
        String prjId = apiService.getPrjId(prjName);
        List<String> images = apiService.getRepositories(prjId);
        List<String> imgs = new ArrayList<>();
        for (String imageName : images) {
            List<String> tags = apiService.getTags(imageName);
            for (String tag : tags) {
                imgs.add("images-docker.zhulong.com.cn/" + imageName + ":" + tag);
            }
        }

        return imgs;
    }
}
